package com.sinodata.bsm.center.service.event;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.sinodata.bsm.center.cache.EventTypeCache;
import com.sinodata.bsm.center.dao.BaseDao;
import com.sinodata.bsm.common.vo.EventType;

@Service
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public class EventTypeService {
    @Autowired
    private EventTypeCache eventTypeCache;
    @Autowired
    private BaseDao baseDao;

    /**
     * 根据资源类别获取事件类型
     * @param resTypeId
     * @return
     */
    public List<EventType> findByResTypeId(Long resTypeId) {
        return eventTypeCache.findByResTypeId(resTypeId);
    }

    public List<EventType> findByResId(Long resId) {
        return eventTypeCache.findByResId(resId);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void add(EventType eventType) {
        baseDao.save(eventType);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void update(EventType eventType) {
        baseDao.update(eventType);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public void delete(Long id) {
        baseDao.delete(eventTypeCache.get(id));
    }
}
